package beer.zivelin.awesome.walawala.mobile;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;

import java.util.List;

import androidx.activity.ComponentActivity;
import beer.zivelin.awesome.walawala.mobile.service.T9;

public class Tester {
    public static final String TAG = "__M_WALAWALA";

    public static void getNewPackage(Activity app) {
    }

    public static void printPinyin(String str) {
        for (String s : T9.getInstance().toT9BySentence(str)) {
            Log.d("MAIN", str + " ==> " + s);
        }
    }

    public static void pinyinTest() {
        printPinyin("mWalaWala-效率工具");
        printPinyin("mWala-Wala-效率工具");
        printPinyin("mWala Wala-效率工具");
        printPinyin("mWala Wala  -  效率工具");
        printPinyin("mWala Wala ``~ 效 率 工 具");
    }

    public static void scanPackageTest(ComponentActivity activity) {
        PackageManager pm = activity.getPackageManager();
        Log.d(Tester.TAG, "start get package");
        Intent query = new Intent();
        query.setAction(Intent.ACTION_MAIN);
        query.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> applications = pm.queryIntentActivities(query,0);
        Log.d(Tester.TAG, "finish get package, count: " + applications.size());
        for (ResolveInfo resolveInfo : applications) {

            Log.d(Tester.TAG,resolveInfo.activityInfo.packageName);
            Log.d(Tester.TAG, "" + resolveInfo.loadLabel(pm));
            Log.d(Tester.TAG, "" + resolveInfo.loadIcon(pm));
            Log.d(Tester.TAG, "---");
            if ("com.flomo.app".equals(resolveInfo.activityInfo.packageName)) {
                Intent resolveIntent = pm.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
                if (resolveIntent != null) {
                    activity.startActivity(resolveIntent);
                }
            }
        }
    }
}
